<template>
  <div class="notice-container">
    <!-- 搜索区域 -->

    <!-- 公告列表 -->
    <div class="table-section">
      <el-table v-loading="loading" :data="noticeList" stripe>
        <el-table-column label="公告标题" align="center" prop="noticeTitle" :show-overflow-tooltip="true" />
        <el-table-column label="发布时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" @click="handleView(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <noticeDetailDialog ref="noticeDetailDialog"></noticeDetailDialog>
  </div>
</template>

<script>
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";

import noticeDetailDialog from "@/components/common/noticeDetailDialog.vue";

import homeApi from "@/api/home/newIndex";
export default {
  name: "Notice",
  dicts: ['sys_notice_status', 'sys_notice_type'],
  components: { noticeDetailDialog },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查看详情弹出层
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: '',
        noticeType: 'sjdtzgg'
      },
      // 表单参数
      form: {},
      // 查看表单
      viewForm: {},
      // 表单校验
      rules: {
        noticeTitle: [
          { required: true, message: "公告标题不能为空", trigger: "blur" }
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      homeApi.baseNotice(this.queryParams).then(response => {
        this.noticeList = response.data;

        this.loading = false;
      });

    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },


    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids
      getNotice(noticeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改公告";
      });
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.$refs.noticeDetailDialog.open(row);
    },


  }
};
</script>

<style lang="scss" scoped>
.notice-container {
  padding: 20px;

  .search-section {
    background: #fff;
    padding: 10px 20px 0;
    margin-bottom: 10px;
    border-radius: 4px;
  }



}

.notice-detail {
  .detail-header {
    border-bottom: 1px solid #ebeef5;
    padding-bottom: 15px;
    margin-bottom: 20px;

    h3 {
      margin: 0 0 10px 0;
      color: #303133;
      font-size: 18px;
      font-weight: 500;
    }

    .detail-meta {
      display: flex;
      flex-wrap: wrap;
      gap: 15px;

      .meta-item {
        display: flex;
        align-items: center;
        color: #606266;
        font-size: 14px;

        i {
          margin-right: 5px;
          color: #909399;
        }
      }
    }
  }

  .detail-content {
    line-height: 1.8;
    color: #606266;
    font-size: 14px;

    ::v-deep {
      img {
        max-width: 100%;
        height: auto;
      }

      p {
        margin: 10px 0;
      }

      ul,
      ol {
        padding-left: 20px;
      }
    }
  }
}

// 响应式适配
@media (max-width: 768px) {
  .notice-container {
    padding: 10px;
  }

  .detail-meta {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .el-table {
    font-size: 12px;
  }
}
</style>
